package top.zerozoo.learn.grade.factory;

import top.zerozoo.learn.grade.service.*;
import top.zerozoo.learn.grade.service.impl.*;

import java.util.concurrent.ConcurrentHashMap;

public class ServiceFactory {
    private static ConcurrentHashMap<Class, IService> daoMap  = new ConcurrentHashMap<>();

    static {
        init();
    }
    @SuppressWarnings("unchecked")
    public static <T extends IService> T get(Class<T> clazz) {
        return (T) daoMap.get(clazz);
    }

    protected static void init() {
        ConcurrentHashMap<Class, IService> map = new ConcurrentHashMap<>();
        map.put(AdminService.class, new AdminServiceImpl());
        map.put(MajorService.class, new MajorServiceImpl());
        map.put(CourseScoreService.class, new CourseScoreServiceImpl());
        map.put(StudentService.class, new StudentServiceImpl());
        map.put(StudentSimpleInfoService.class, new StudentSimpleInfoServiceImpl());
        daoMap = map;
    }
}
